#include"Queue.h"
bool QueueEmpty(Queue* s)
{
	assert(s);
	return s->head == NULL
		&& s->tail == NULL;
}
void Queueinit(Queue* s)
{
	assert(s);
	s->head = NULL;
	s->tail = NULL;
	s->size = 0;
}
void QueuePush(Queue* s, Datatype x)
{
	Qnode* newnode = (Qnode*)malloc(sizeof(Qnode));
	assert(s);
	assert(newnode);
	newnode->data = x;
	newnode->next = NULL;
	if (s->head == NULL)
	{
		s->head = newnode;
		s->tail = newnode;
	}
	else
	{
		s->tail->next = newnode;
		s->tail = newnode;
	}
	s->size++;
}
void QueuePop(Queue* s)
{
	assert(s);
	assert(!QueueEmpty(s));
	if (s->head->next == NULL)
	{
		//Qnode* cut = s->head;
		free(s->head);
		s->head = NULL;
		s->tail = NULL;
	}
	else
	{
		Qnode* cut = s->head->next;
		free(s->head);
		s->head = cut;
	}
	s->size--;
}
Datatype QueueFront(Queue* s)
{
	assert(s);
	Datatype cut = s->head->data;
	QueuePop(s);
	return cut;
}
void QueueDestory(Queue* s)
{
	assert(s);
	//assert(!QueueEmpty(s));
	if (QueueEmpty(s))
	{
		return;
	}
	while (s->head)
	{
			Qnode* cut = s->head->next;
			free(s->head);
			s->head = cut;
			s->tail = NULL;
			s->size = 0;
	}
}